apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service","../../dialog"],function(V,$api,$,app,service,dialog){
	var vm = {
		el: '.container',
	  	data: {
				activityList: '',
				tabIndex: 0,
				page: 1
	  	},
	  	mounted:function() {

	  	},
	  	methods:{
				next: function(){
					$(".shop-activity-name").css("display", "none");
					$(".shop-activity-list").css("display", "block");
					$(".shop-activity-btn").css("display", "block");
					this.getShopActivity();
				},
				//获取店铺（优惠券）活动
				getShopActivity: function(){
					var that = this;
					var unionid =  $api.getStorage("shop_unionid");
					console.log("xxx: "+unionid);
					app.ajax(service['getCouponActiveList'],
					{
						data: {
							values: {
								shop_code: api.pageParam.shopId,
								unionid: unionid,
								is_active: '',
                page: this.page,
							}
						}
					},
					function (res) {
						// var shopCode = res.data.shop_code; // 商店id
						if(res.code){
							alert("错误号码code："+res.code+"\n错误信息："+res.message)
						}else{
							if(res.data == ''){
								that.tabIndex = 1;
							}else{
								that.tabIndex = 0;
							}
							that.activityList = res.data;
							console.log(JSON.stringify(that.activityList))
							console.log("获取店铺活动列表成功!");
						}
					}
					);
				},
				//--添加店铺活动页面
	    	openShopActivityAdd: function(et){
					app.openWin('shopActivityAdd',{shopId: api.pageParam.shopId})
	    	},
				//--删除店铺活动
				ShopActivityDel: function(coupon_id){
					var that = this;

					dialog.alert({
              title: "店铺活动回收提示",
              msg: '请确认是否删除该店铺活动',
              buttons: ['取消', '确定']
          }, function(ret) {
						if(ret.buttonIndex == 2){ //确认
							app.ajax(service['delCouponActive'],
							{
								data: {
									values: {
										shop_code: api.pageParam.shopId,
										unionid: $api.getStorage("shop_unionid"),
										coupon_id: coupon_id,
									}
								}
							},
							function (res) {
								// var shopCode = res.data.shop_code; // 商店id
								if(res.code){
									alert("错误号码code："+res.code+"\n错误信息："+res.message)
								}else{
									api.toast({
											msg: '店铺活动已删除',
											duration: 2000,
											location: 'middle'
									});
									console.log(res.data)
									console.log("删除店铺活动成功!");
									that.getShopActivity();
								}
							}
							);
						}
					});


	    	},
	  	},
			created: function(){
				var that = this;

				//--监听添加店铺活动之后刷新该活动列表。
				api.addEventListener({
				    name: 'refresh'
				}, function(ret, err){
				    that.getShopActivity();
				});
			}
	};

	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
